import {getById} from '../services/product'
import {imageArrayToList} from '../utils'
export default {
    namespaced:true,
    state:{
        visible:false,
        product:{}
    },
    mutations:{
        setVisible(state,visible){
            state.visible = visible;
        },
        setProduct(state,product){
            state.product = {...product};
        }
    },
    actions:{
        async showById({commit},id){
            let product = await getById(id);
            product['indexImageList'] = imageArrayToList(product.indexImages);
            product['detailImageList'] = imageArrayToList(product.detailImages);
            commit('setProduct',product);
        }
    }
}